package excercise;

public class EX32 {
	// 주민번호 유효성 검사
	// 123456-1234567
	// 1*2 + 2*3 + 3*4 + 4*5 + 5*6 + 6*7
	// 1*8 + 2*9 + 3*2 + 4*3 + 5*4 + 6*5
	public static void main(String[] args) {
		// 123456 
		// 123456 / 100000 => 1
		// 123456 % (1*100000) = 23456
		// 23456 / 10000 => 2
		// 23456 % (2*10000) => 3456
		// 3456 / 1000 => 3
		// 3456 % (3*1000) => 456
		
		long jumin = 9104221273117L;
		int key = 0; 		// 추출된 각 자릿수 값
		int total = 0;
		
		//첫쨰 자리
		key = (int)(jumin / 1000000000000l);
		total = total + (key *2);
		jumin = jumin %(key * 1000000000000l);
		// 둘쨰짜리
		key = (int)(jumin / 100000000000l);
		total = total +(key * 3);
		if( key > 0) jumin = jumin %(key * 100000000000l);
		//셋쨰자리
		key = (int)(jumin / 10000000000l);
		total = total +(key * 4);
		if( key > 0)jumin = jumin %(key * 10000000000l);
		//넷쨰자리
		key = (int)(jumin / 1000000000l);
		total = total +(key * 5);
		if( key > 0)jumin = jumin %(key * 1000000000l);
		//다섯쨰자리
		key = (int)(jumin / 100000000l);
		total = total +(key * 6);
		if( key > 0)jumin = jumin %(key * 100000000l);
		//여섯쨰자리
		key = (int)(jumin / 10000000l);
		total = total +(key * 1);
		if( key > 0)jumin = jumin %(key * 10000000l);
		//7쨰자리
		key = (int)(jumin / 1000000l);
		total = total +(key * 2);
		if( key > 0)jumin = jumin %(key * 1000000l);
		//8
		key = (int)(jumin / 100000l);
		total = total +(key * 3);
		if( key > 0)jumin = jumin %(key * 100000l);
		//9
		key = (int)(jumin / 10000l);
		total = total +(key * 4);
		if( key > 0)jumin = jumin %(key * 10000l);
		//10
		key = (int)(jumin / 1000l);
		total = total +(key * 4);
		if( key > 0)jumin = jumin %(key * 1000l);
		//11
		key = (int)(jumin / 100l);
		total = total +(key * 5);
		if( key > 0)jumin = jumin %(key * 100l);
		//12
		key = (int)(jumin / 10l);
		total = total +(key * 6);
		if( key > 0)jumin = jumin %(key * 10l);
		// 반복문으로 처리
		//System.out.println(Math.pow(10, 12));
		 
		jumin = 9104221273117L;
		total = 0;
		
		for(long divider = 1000000000000L, prime = 2;
				divider >= 10L; divider/= 10, ++prime){
			if (prime > 9) prime = 2;
			key = (int)(jumin / divider);
			
			total = total +(key * (int)prime);
			if(key > 0) jumin = jumin % (key * divider);
		}
		
		System.out.println(jumin);
		//System.out.println(total);
			System.out.println((11-total%11)%10);
			if(jumin == (11-total%11)%10){
				System.out.println("정상입니다");
			} else{
				System.out.println("틀립니다");
			}
			
			
				
			}
	}	


